Skip to main content

FHIRPath

API

evaluate

Returns a JS object/primitive based on the evaluation.

evaluate(
expression: string,
ctx: unknown,
options?: Options
): NonNullable<unknown>[]

evaluateWithMeta

Returns a @iguhealth/meta-value singular value which contains data along with metadata about the evaluation.

function evaluateWithMeta(
expression: string,
ctx: unknown,
options?: Options,
): MetaValueSingular<NonNullable<unknown>>[];

Arguments

nametypedescription
expressionstringFHIRPath expression to evaluate.
ctxunknownThe context which the fhirpath is being evaluated from (sets $this context).
optionsObjectIncludes variables and metadata deriviation functions.
options.variablesObject | FunctionIf an object is Record<variableName, variableValue> else (variableName)=> variableValue.
options.metaObjectMetaInformation used to zip metadata with value. Used in type functions and operators.
options.meta.typestringRoot type for ctx.
options.meta.getSD(fhir_version: FHIRVersion, type: string) => StructureDefinitionReturns a StructureDefinition based on type passed in.

Usage

import * as fhirpath from "@iguhealth/fhirpath";

// Default returns javascript object.
expect(fhirpath.evaluate("4 + 5", {})).toEqual([9]);
expect(fhirpath.evaluate("$this.test + 2 * 4", { test: 4 })).toEqual([12]);

// Evaluation with metavalue return (returns value in addition to meta information.)
expect(
evaluateWithMeta(
"$this.name",
{
resourceType: "Patient",
name: [{ given: ["bob"], family: "jameson" }],
},
{
meta: {
type: "Patient",
getSD: (fhirVersion, type: code) => {
const foundSD = sds.find((sd) => sd.type === type);
return foundSD;
},
},
},
).map((v) => v.meta()?.type),
).toEqual(["HumanName"]);

Operations supported

OperationDescriptionSupported
+ (addition)Concatenate strings or add values if numeric.true
- (subtraction)Subtracts the right operand from the left operand.true
as type specifierReturns left operand if value is of type specified.true
is(type : type specifier)Filters left operand based on type specifier.true
* (multiplication)Multiplies both arguments.true
/ (division)Divides the left operand by the right operandtrue
| (union collections)Merge the two collections into a single collectiontrue
= (Equals)Returns true if the left collection is equal to the right collectiontrue
!= (Not Equals)Converse operator of equals returns true if left collection is not equal to right collectiontrue

Supported Functions

NameDescriptionSupported
emptyReturns true if the input collection is empty () and false otherwise.true
existsReturns true if the collection has any elements, and false otherwise.true
allReturns true if for every element in the input collection, criteria evaluates to true.true
allTrueTakes a collection of Boolean values and returns true if all the items are true.true
anyTrueTakes a collection of Boolean values and returns true if any of the items are true.true
allFalseTakes a collection of Boolean values and returns true if all the items are false.true
anyFalseTakes a collection of Boolean values and returns true if any of the items are false.true
subsetOfReturns true if all items in the input collection are members of the collection passed in.true
supersetOfReturns true if all items in the collection passed as the other argument are members of the input collection.true
countReturns the integer count of the number of items in the input collection.true
distinctReturns a collection containing only the unique items in the input collection.true
isDistinctReturns true if all the items in the input collection are distinct.true
whereReturns a collection containing only those elements in the input collection based on where expression.true
selectEvaluates the projection expression for each item in the input collection.true
repeatA version of select that will repeat the projection and add it to the output collection.true
ofTypeReturns a collection that contains all items in the input collection that are of the given type.true
asReturns filter same as ofType used for backwards compatibility.true